<template>
  <el-container>
    <el-header>
      <div class="header-content">
        建筑业从业人员继续教育考试系统
      </div>
    </el-header>
    <el-main v-loading="loading">
      <el-row type="flex" class="row-bg" justify="center" :gutter="12" style="align-items: center;">
        <el-col :span="7">
          <el-card shadow="always">
            <div class="time" slot="header">
              考试信息
            </div>
            <div style="min-height: 320px;">
              <el-row class="user-item">
                <el-col :span="7" class="user-title">考生姓名：</el-col>
                <el-col :span="17">{{ userInfor && userInfor.userName }}</el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="7" class="user-title">身份证号：</el-col>
                <el-col :span="17">{{ userInfor && userInfor.idCard }}</el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="7" class="user-title">考生性别：</el-col>
                <el-col :span="17">{{ userInfor && userInfor.gender }}</el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="7" class="user-title">企业名称：</el-col>
                <el-col :span="17">{{ userInfor && userInfor.orgName }}</el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="7" class="user-title">考试类别：</el-col>
                <el-col :span="17">{{ userInfor && userInfor.userRole }}</el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="7" class="user-title">考试时间：</el-col>
                <el-col :span="17">{{ examInfor && examInfor.startTime }}-{{ examInfor && examInfor.endTime }}</el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="7" class="user-title">答卷时间：</el-col>
                <el-col :span="17">{{ examInfor && examInfor.singleTime }}分钟</el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="7" class="user-title">试题详情：</el-col>
                <el-col :span="17">
                  <span v-for="(item, index) in examInfor.examQusList">
                    {{ item.qusTypeDesc }}{{ item.qusNum }}题，每题{{item.qusScore}}分，
                  </span>
                  <span>总计{{ examInfor && examInfor.qusNum }}题</span>
                </el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="7" class="user-title">合格规则：</el-col>
                <el-col :span="17">{{ examInfor && examInfor.passScore }}分及格（满分{{ examInfor && examInfor.totalScore }}分）</el-col>
              </el-row>
              <el-row class="user-item">
                <el-col :span="24">
                    <el-alert
                      title="温馨提示:计时结束系统将会自动提交试卷，请检查是否答题完毕"
                      type="warning" show-icon :closable="false">
                    </el-alert>
                </el-col>
              </el-row>
              <el-row  type="flex" class="user-item" justify="center" style="margin-top: 56px;">
                <el-col :span="12">
                  <el-button type="primary" @click="handleSubmit" style="width: 100%;">开始考试</el-button>
                </el-col>
              </el-row>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </el-main>
    <el-footer>
      <span>技术支持：贵阳市金阳建设数据服务有限公司</span>
    </el-footer>
  </el-container>
</template>

<script>
  import request from '@/utils/request'
  export default {
    name: 'ExamConfirm',
    data() {
      return {
        Urls: {
          examGetByExamIdUrl: '/api/exam/detail/get/',
          // 当前用户信息
          currentUserInfoUrl: '/api/examUser/query',
          // 考试结果
          resultUrl: '/api/exam/record/result/',
        },
        examId: localStorage.getItem('examId'),
        examType: localStorage.getItem('examType'),
        name: localStorage.getItem('name'),
        userName: localStorage.getItem('mark'),
        id: localStorage.getItem('id'),
        examInfor: {
          qusNum: 0,
          totalScore: 0,
          passScore: 0,
          period: '',
          examQusList: [],
          singleTime: 0
        },
        userInfor: {},
        loading: false
      }
    },
    created() {
      // 获取考试信息
      this.getExamInfo()
      // 获取用户信息
      this.getUserInfo()
    },
    methods: {
      /**
       * 考试时间
       */
      getExamTime() {
        const _this = this
        request({
          url: _this.Urls.resultUrl + _this.examId,
          method: 'get',
          data: {}
        }).then(res => {
          if (res.code == 0) {
            if (res.data && res.data.results[0] && res.data.results[0].submit) {
              _this.$router.push({
                path: '/exam-result'
              })
            } else {
              _this.$router.push({
                path: '/exam-home'
              })
            }
          } else{
            _this.$notify.error({
              message: res.msg
            })
          }
        })
      },
      /**
       * 开始考试
       */
      handleSubmit() {
        const _this = this
        this.$confirm('开始考试后请勿中途退出、挂机或返回其他页面，若因以上问题导致无法继续考试，后果自行承担')
         .then(_ => {
            this.getExamTime()
         }).catch(_ => {

         })
      },
      getExamInfo() {
        const _this = this
        request({
          url: _this.Urls.examGetByExamIdUrl + _this.examId,
          method: 'get',
          data: {}
        }).then(res => {
          if (res.code == 0) {
            _this.examInfor = {
              qusNum: res.data.qusNum,
              totalScore: res.data.totalScore,
              passScore: res.data.passScore,
              period: res.data.period,
              examQusList: res.data.examQusList,
              singleTime: res.data.singleTime,
              startTime: res.data.startTime,
              endTime: res.data.endTime,
            }
          } else{
          }
        })
      },
      getUserInfo() {
        const _this = this
        _this.loading = true
        request({
          url: _this.Urls.currentUserInfoUrl,
          method: 'post',
          data: {
            userId: _this.id,
            examId: _this.examId
          }
        }).then(res => {
          _this.loading = false
          if (res.code == 0) {
            _this.userInfor = {
              ...res.data.records[0]
            }
          } else{
          }
        })
      }
    }
  }
</script>

<style scoped="scoped">
  .el-container {
    height: 100vh;
    flex-direction: column;
  }

  .el-header, .el-footer {
      background-color: #B3C0D1;
      line-height: 60px;
    }
    .el-header {
      background-color: #fff;
    }
    .header-content {
      width: 90%;
      margin: 0 auto;
      color: #1a8cff;
      font-size: 24px;
    }
    .el-footer {
      font-weight: 400;
      text-align: center;
      background-color: #000;
      color: #fff;
    }
    .el-main {
      flex: 1;
      overflow: auto;
      background-color: #E9EEF3;
    }
    .clearfix:before,
    .clearfix:after {
        display: table;
        content: "";
    }
    .clearfix:after {
      clear: both
    }
    .qus-title-header {
      text-align: center;
    }
    .qus-title {
      font-weight: bold;
      font-size: 16px;
    }
    .qus-content {
      min-height: 400px;
    }
    .qus-info {
      margin-top: 12px;
      font-size: 14px;
    }
    .other-gutter {
      margin-top: 12px;
    }
    .time {
      text-align: center;
      font-size: 20px;
    }
    .qus-item {
      margin-bottom: 24px;
    }
    .qus-item-title {
      font-weight: bold;
      margin-bottom: 12px;
    }
    .qus-subject {
      margin-top: 16px;
      line-height: 24px;
    }
    .qus-option-content {
      margin-top: 24px;
    }
    .qus-option-content .el-radio {
      margin-bottom: 12px;
      display: block;
    }
    .qus-option-content .is-checked span:first-child {
      background-color: #409eff;
      color: #fff;
    }
    .qus-option-item {
      display: inline-block;
      padding: 4px;
      height: 24px;
      width: 24px;
      border-radius: 24px;
      border:1px solid #DCDFE6;
      vertical-align: middle;
      text-align: center;
      margin-right: 12px;
    }
    .qus-btn-group {
      margin-top: 48px;
      text-align: center;
    }
    .qus-btn-group button {
      width: 100px;
    }
    .qus-btn-group button:first-child {
      margin-right: 24px;
    }
    .sub-btn {
      width: 100%;
      text-align: center;
      padding-top: 32px;
    }
    .user-item {
      margin-bottom: 24px;
    }
    .user-title {
      text-align: right;
      color: #a3a49d;
    }
</style>
